<script setup lang="ts">
import { ref } from "vue";
import { genFileId } from "element-plus";
import type { UploadInstance, UploadProps, UploadRawFile } from "element-plus";
const { VITE_PUBLIC_PATH } = import.meta.env;
const upload = ref<UploadInstance>();
const action = ref(`${VITE_PUBLIC_PATH}/api/upload`);
// console.log("aaaa=" + action.value);
const handleExceed: UploadProps["onExceed"] = files => {
  upload.value!.clearFiles();
  const file = files[0] as UploadRawFile;
  file.uid = genFileId();
  upload.value!.handleStart(file);
  console.log("handleExceed", file);
};
const submitUpload = () => {
  upload.value!.submit();
};
</script>

<template>
  <el-upload
    ref="upload"
    class="upload-demo"
    :action="action"
    :limit="1"
    :on-exceed="handleExceed"
    :show-file-list="false"
  >
    <template #trigger>
      <el-button type="primary">上传图片</el-button>
    </template>
  </el-upload>
</template>
